package com.zenghm.retrofit2.adapter;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;

import java.lang.reflect.Type;

import retrofit2.Call;
import retrofit2.CallAdapter;

/**
 * <p>2021-04-15: create by zenghm</P>
 */
final class LiveDataCallAdapter<T> implements CallAdapter<T, LiveData<T>> {

    private final Type responseType;

    public LiveDataCallAdapter(Type responseType) {
        this.responseType = responseType;
    }

    @NonNull
    @Override
    public Type responseType() {
        return responseType;
    }

    @NonNull
    @Override
    public LiveData<T> adapt(@NonNull Call<T> call) {
        return new SafeLiveData<>(call);
    }
}
